package com.lfd.springasync.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.springasync.config
 * @文件名: AsyncConfig
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/13 21:37
 * @描述：
 */
@Configuration
public class AsyncConfig {
    @Bean(name = "taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);  // 核心线程数
        executor.setMaxPoolSize(10);  // 最大线程数
        executor.setQueueCapacity(100);  // 队列大小
        executor.setThreadNamePrefix("AsyncThread-");  // 线程名前缀
        executor.initialize();
        return executor;
    }
}
